from selenium.webdriver.common.by import By

from base.page_base import PageBase


class AddressPage(PageBase):
    """地址管理页面"""
      # 元素定位
    # 1. 个人
    __mine = (By.XPATH, '//android.widget.TextView[@text="个人"]')
    # 2. 设置
    __setting = (By.ID, 'com.netease.yanxuan:id/ivSetting')
    # 3. 我的地址
    __address = (By.XPATH, '//android.widget.TextView[@text="我的地址"]')
    # 4. 新增地址
    __add_address = (By.XPATH, '//android.widget.TextView[@text="新建地址"]')
    # 5. 下拉选中省份、市、县
    __province = (By.XPATH, '//android.widget.TextView[@text="北京市"]')
    __city = (By.XPATH, '//android.widget.TextView[@text="顺义区"]')
    __county = (By.XPATH, '//android.widget.TextView[@text="马坡地区"]')
    # 6.确定
    __confirm = (By.ID, 'com.netease.yanxuan:id/btn_confirm_address_manage')
    # 7.详细地址
    __detail_address = (By.ID, 'com.netease.yanxuan:id/address_detial_edit')
    # 8.姓名
    __name = (By.ID, 'com.netease.yanxuan:id/address_name_edit')
    # 9.手机号
    __phone = (By.ID, 'com.netease.yanxuan:id/address_phonenumber_edit')
    # 10.保存
    __save = (By.ID, 'com.netease.yanxuan:id/nav_right_text')
    #成功结果
    __success_result = (By.XPATH, '//android.widget.TextView[@text="王先生"]')
    #操作方法
    def click_mine(self):
        """点击个人"""
        self.base_click(self.__mine)

    def click_setting(self):
        """点击设置"""
        self.base_click(self.__setting)

    def click__my_address(self):
        """点击我的地址"""
        self.base_click(self.__address)

    def select_address(self):
        """点击新增地址，选择前三级"""
        self.base_click(self.__add_address)
        self.base_click(self.__province)
    def select_city(self,x=500,start_y=1800,end_y=1000):
        #滑动区域
        self.base_swipe(x,start_y,x,end_y)
        self.base_click(self.__city)
        #滑动
    def select_county(self,x=500,start_y=1800,end_y=1700):
        self.base_swipe(x,start_y,x,end_y)
        self.base_click(self.__county)
        self.base_click(self.__confirm)

    def input_detail_address(self, detail,name,phone):
        """输入详细地址"""
        self.base_input_text(self.__detail_address, detail)
        self.base_input_text(self.__name, name)
        self.base_input_text(self.__phone, phone)
        self.base_click(self.__save)
    def add_default_address(self,detail,name,phone):
        """添加默认地址"""
        self.click_mine()
        self.click_setting()
        self.click__my_address()
        self.select_address()
        self.select_city()
        self.select_county()
        self.input_detail_address(detail,name,phone)
    def get_success_result(self,text):
        """获取成功结果"""
        return self.base_get_text(self.__success_result)